package com.ibeetl.cms.service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

import com.ibeetl.admin.core.entity.CoreUser;
import com.ibeetl.admin.core.service.CorePlatformService;
import org.apache.poi.ss.formula.functions.T;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ibeetl.admin.core.util.PlatformException;

import com.ibeetl.cms.dao.BusinessProcessDao;
import com.ibeetl.cms.entity.BusinessProcess;
import com.ibeetl.admin.core.service.BaseService;
/**
 * BusinessProcess Service
 */

@Service
@Transactional
public class BusinessProcessService extends BaseService<BusinessProcess>{

    @Autowired private BusinessProcessDao businessProcessDao;


    @Autowired
    CorePlatformService platformService;

    public PageQuery<BusinessProcess>queryByCondition(PageQuery query){
        PageQuery ret =  businessProcessDao.queryByCondition(query);
        queryListAfter(ret.getList());
        return ret;
    }

    public void batchDelBusinessProcess(List<Long> ids){
        try {
            businessProcessDao.batchDelBusinessProcessByIds(ids);
        } catch (Exception e) {
            throw new PlatformException("批量删除BusinessProcess失败", e);
        }
    }

    /**
     * 审核流程
     */
    public void processInformation(Integer business_id, String business_state,String business_state_code,
                                   String handle_suggestion, String process_result, String businessType){

        BusinessProcess businessProcess = new BusinessProcess();
        businessProcess.setBusinessId(business_id);
        businessProcess.setBusinessState(business_state);
        businessProcess.setBusinessStateCode(business_state_code);
        businessProcess.setHandlingSuggestion(handle_suggestion);
        businessProcess.setProcessResult(process_result);
        businessProcess.setBusinessType(businessType);

        CoreUser user = platformService.getCurrentUser();
        long process_username_id = user.getId();
        String process_username = user.getName();
        businessProcess.setProcessUserId(process_username_id);
        businessProcess.setProcessUserName(process_username);

        java.util.Date date=new java.util.Date();
        businessProcess.setProcessTime(date);
        this.save(businessProcess);
    }

    public List<BusinessProcess> findBusiness(String business_type) {
        return businessProcessDao.findBusiness(business_type);
    }
}